package com.springboot2.service.Impl;

import com.springboot2.entity.Banner;
import com.springboot2.mapper.BannerMapper;
import com.springboot2.service.BannerService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class BannerServiceImpl implements BannerService {

    @Resource
    private BannerMapper bannerMapper;

    @Override
    public void add(Banner banner) {
        Date date = new Date();
        banner.setCreateTime(date);
        banner.setIsDel(1);
        bannerMapper.add(banner);

    }

    @Override
    public void del(int id) {
        bannerMapper.del(id);
    }

    @Override
    public void update(Banner banner) {
        Date date = new Date();
        banner.setCreateTime(date);
        banner.setIsDel(1);
        bannerMapper.update(banner);
    }

    @Override
    public Banner findById(int id) {
        return bannerMapper.findById(id);
    }

    @Override
    public List<Banner> findByPage(int pageNo,int pageSize) {
        Map<String ,Integer> map = new HashMap<>();
        map.put("pageNo",(pageNo-1)*pageSize);
        map.put("pageSize",pageSize);
        return bannerMapper.findByPage(map);
    }

    @Override
    public int count() {
        return bannerMapper.count();
    }

    @Override
    public List<Banner> findByPageParams(int pageNo,int pageSize,String title) {
        Map<String ,Object> map = new HashMap<>();
        map.put("pageNo",(pageNo-1)*pageSize);
        map.put("pageSize",pageSize);
        map.put("title",title+"%");
        return bannerMapper.findByPageParams(map);
    }

    @Override
    public int countParams() {
        return bannerMapper.countParams();
    }

    @Override
    public List<Banner> findByStatus() {
        return bannerMapper.findByStatus();
    }
}
